package com.game.gameshoppingcenter.controller;

import com.game.gameshoppingcenter.dao.OrdersRepository;
import com.game.gameshoppingcenter.entities.Orders;
import com.game.gameshoppingcenter.entities.Users;
import com.game.gameshoppingcenter.service.OrdersService;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Order")
public class OrdersController {
    @Autowired
    OrdersService ordersService;
    @Autowired
    OrdersRepository ordersRepository;
    @RequestMapping("/save")
    public String dingdan(Model model, Orders orders){

         ordersService.save(orders);

        return "Shoppingstore/shoppingstore";
    }
    @RequestMapping("/toshow")
    //把数据库订单信息渲染到订单页面中
    public String toshow( Model model){
        List<Orders> orders=ordersService.getorders();
        model.addAttribute("orders1",orders);
        System.out.println(orders);
        return "Dingdan/Dingdan";

    }
    //订单页面中的删除功能
    @RequestMapping("/delect/{id}")
    public String delect(@PathVariable("id") long id, Orders orders , Model model){
        Orders orders1=ordersService.findByOrdersId(id);

        ordersService.delect(orders1);
        return "redirect:/Order/toshow";



    }

}
